using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using Rocuna.GameEngine.Extension.WP7.Input.Constants;
using Rocuna.GameEngine.Input;
using System.Linq;

namespace Rocuna.GameEngine.Extension.WP7.Input
{
    /// <summary>
    /// Input device for the Phone touch screen.
    /// </summary>
    public class PhoneTouchScreenDevice : GameComponent, IInputDevice
    {
        private bool _isActive;

        /// <summary>
        /// Initializes a new instance of the <see cref="PhoneTouchScreenDevice"/> class.
        /// </summary>
        public PhoneTouchScreenDevice(Game game)
            : base(game)
        {
            Dictionary = new ActionsDictionary();
            _isActive = false;
        }

        /// <summary>
        /// Gets or sets the dictionary.
        /// </summary>
        /// <value>
        /// The dictionary.
        /// </value>
        public ActionsDictionary Dictionary { get; set; }

        #region Implementation of IInputDevice

        /// <summary>
        /// Gets the name of the device.
        /// </summary>
        /// <value>
        /// The name of the device.
        /// </value>
        public string DeviceName
        {
            get { return PhoneDevices.PhoneTouchScreen; }
        }

        /// <summary>
        /// Polls this device for input status.
        /// </summary>
        public void Poll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Registers action to specified event.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="action">The action.</param>
        public void RegisterAction(object eventType, Action<object> action)
        {
            Dictionary.Add(eventType, action);
        }

        /// <summary>
        /// UnRegister action to specified event.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        public void UnRegisterAction(object eventType)
        {
            Dictionary.Remove(eventType);
        }

        /// <summary>
        /// Gets a value indicating whether this instance is active.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is active; otherwise, <c>false</c>.
        /// </value>
        public bool IsActive
        {
            get
            {
                return _isActive;
            }
        }

        /// <summary>
        /// Unactive the device.
        /// </summary>
        public void DeActiveDevice()
        {
            _isActive = false;
            Game.Components.Remove(this);
        }

        /// <summary>
        /// Activates the device.
        /// </summary>
        public void ActivateDevice()
        {
            _isActive = true;
            Game.Components.Add(this);
        }

        /// <summary>
        /// Clears this instance actions.
        /// </summary>
        public void Clear()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region

        protected override void Dispose(bool disposing)
        {
            DeActiveDevice();
            base.Dispose(disposing);
        }

        public override void Update(GameTime gameTime)
        {
            Poll();
            base.Update(gameTime);
        }

        #endregion
    }
}